<template>
  <div v-loading="loading" element-loading-text="模型生成中...">
    <div style="width: 280px; border: 1px solid white;">
      <el-form  ref="form"  label-width="90px">
        <el-form-item label="模数">
          <el-input size="small" v-model.number="m" onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.charCode== 46" type="number" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="齿数">
          <el-input size="small" v-model.number="z2"  onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.charCode== 46" type="number" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="变位系数">
          <el-input size="small" v-model.number="zx" onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.charCode== 46" type="number" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="厚度">
          <el-input size="small" v-model.number="b2" type="number" onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.charCode== 46" placeholder="请输入内容" >
            <i slot="suffix" style="font-style:normal; color: #606266;">mm</i>
          </el-input>
        </el-form-item>
        <el-form-item label="压力角">
          <el-input size="small" v-model.number="alpha" type="number" onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.charCode== 46" placeholder="请输入内容">
            <i slot="suffix" style="font-style:normal; color: #606266;">°</i>
          </el-input>
        </el-form-item>
        <el-form-item label="齿顶高系数">
          <el-input size="small" v-model.number="Ha" onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.charCode== 46" type="number" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="顶隙系数">
          <el-input size="small" v-model.number="C" onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.charCode== 46" type="number" placeholder="请输入内容"></el-input>
        </el-form-item>
      </el-form>
      <div>
        <img src="/image/worm.png" height="200" width="280"/>
        <div style="margin-top: 20px;text-align: center">
          <el-button type="primary" size="small" @click="creatWormGear">确定</el-button>
          <el-button size="small" @click="closeDialog">取消</el-button>
        </div>
      </div>
    </div>


  </div>
</template>

<script>
  import {
    Axis,
    CrownCADPlugin,
    Direction, PluginCADToolFunctionType,
    PluginFunctionType,
    Point
  } from "../../../../nodeApp/static/lib/crowncad-plugin-sdk-0.0.1";
  export default {
    name: "WormGear",
    data() {
      return {
        loading:false,
        m: 2.5,   // 模数
        z2: 40, //头数
        zx: 0,  //变位系数
        alpha: 20,   // 压力角
        I:0,  //导程
        z1: 1, //头数
        pressureAngle:0, //压力角换算弧度
        b2:16,  // 厚度
        q: 11.2, // 直径系数
        Ha: 1,  //齿顶高系数
        C:0.2,  //顶隙系数
        ha2:0,  //齿顶高
        hf2:0,  //齿根高
        da2:0,  //喉圆
        df2:0,  //齿根圆
        da2id:0,  //喉圆id
        df2id:0,  //齿根圆id
        d2:0, //分度圆
        d1:0, //分度圆
        a:0, //中心距
        db:0, //基圆
        de2:0, //最大圆
        axisId:0, //镜像轴id
        EquationId:0, // 第一条渐开线id
        EquationP: {}, // 第一条渐开线终点
        EquationS:{}, // 第一条渐开线起点
        EquationId1:0, // 第二条渐开线id
        EquationP1: {}, // 第二条渐开线终点
        EquationS1:{}, // 第二条渐开线起点
        crownCADPlugin: null,
        currentPickElement:null,
        planeFrontId:0
      }
    },
    mounted() {
      //创建插件对象
      this.crownCADPlugin = new CrownCADPlugin();
      //设置CrownCAD平台地址
      this.crownCADPlugin.setParentOrigin(window.url);
      //.设置与CrownCAD平台尝试建立连接的次数
      this.crownCADPlugin.setMaxAttempt(5);
      //设置插件在CrownCAD平台显示的尺寸
      this.crownCADPlugin.setLayout(315, 315, 610);
      //.发送与CrownCAD平台建立连接的请求

      this.crownCADPlugin.connect().then(() => {
        console.log("connected!");
        this.crownCADPlugin.request.execFunction(PluginFunctionType.LAYOUT, {minWidth: 300, width: 300, maxHeight: 595})
      });
    },
    methods: {
      updateData() {
        this.pressureAngle = (this.alpha / 180) * Math.PI;
        this.d1 = this.m * this.q;
        this.ha2 = this.m * this.Ha;

        this.hf2 = this.m * this.Ha + this.C * this.m


        this.d2= this.m * this.z2;

        this.da2 = this.d2 + 2 * this.ha2;

        this.df2 = this.d2 - this.hf2 * 2

        this.a= (this.d2 + this.d1) * 0.5

        this.db= this.d2* Math.cos(this.pressureAngle)

        this.de2= this.da2 + this.m

        this.I = this.m * this.z1 * Math.PI

	      //厚度
        let j = Math.asin(this.b2 / this.d1)
	      if(!j || j === NaN) {
          let message = '请重新输入厚度'
          let msg = {type: 'warning', description: message}
          this.crownCADPlugin.event.messageTip(msg)
          return false
	      } else {
          //计算出de2/2的点与线的相对位置
          let startP = new Point(0, this.a, 0)
          let endP = new Point(2* this.b2* Math.sin(j), this.a- 2* this.b2* Math.cos(j), 0)
		      //圆上点
		      let cP = new Point(this.b2 / 2, this.de2 / 2, 0)
          if(cP.x < endP.x && cP.x > startP.x && cP.y < startP.y && cP.y > endP.y) {
            let vX = endP.x - startP.x;
            let vY = endP.y - startP.y;
            let wX = cP.x - startP.x;
            let wY = cP.y - startP.y;
            let cross = vX * wY - vY * wX;
            if(cross > 0) {
              return true
            } else {
              let message ='请重新输入厚度'
              let msg = {type: 'warning', description: message}
              this.crownCADPlugin.event.messageTip(msg)
              return false
            }
          } else {
            let message = '请重新输入厚度'
            let msg = {type: 'warning', description: message}
            this.crownCADPlugin.event.messageTip(msg)
            return false
          }
        }
        return true
      },

      closeDialog() {
        this.crownCADPlugin.request.execFunction(PluginCADToolFunctionType.CLOSEACTIVECMD, null);
      },

      //创建蜗轮
      async creatWormGear() {
        // 更新数据
        let status = this.updateData()
	      if(!status) {
          return
	      }

        this.loading = true

        //创建草图，命名为草图0，准备画齿形
        this.crownCADPlugin.command.sketch.createSketch({sketchName: '草图0', datumId: 8});
        // 绘制渐开线
        this.crownCADPlugin.command.sketch.createEquationCurve({
          equationType: 2,
          coordinateType: 1,
          equation1: 0.5* this.db + "*(sin(t+pi/2+0.024)-t*cos(t+pi/2+0.024))",
          equation2: 0.5* this.db + "*(t*sin(t+pi/2+0.024)+cos(t+pi/2+0.024))",
          startValue: 0,
          endValue: 1
        });
        // 绘制镜像轴
        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(0,0,0),
          endPoint:new Point( 0,0.5* this.de2 + 10,0)
        })
        //退出草图
        this.crownCADPlugin.command.sketch.exitSketch();
        //实现草图操作，参数true会覆盖之前的草图，不传则不会
        await this.crownCADPlugin.command.execute(true)

        this.crownCADPlugin.command.clearCommand();

        //获取渐开线和镜像线的id
        await this.getLineInfo()

        //编辑草图0
        this.crownCADPlugin.command.sketch.editSketch({sketchName: '草图0'});
        // 创建镜像线
        // this.crownCADPlugin.command.sketch.createSketchLine({
        //   startPoint: new Point(0,0,0),
        //   endPoint:new Point( 0,200,0)
        // })
        //设置镜像线
        this.crownCADPlugin.command.sketch.setReference({curveIds: [this.axisId], reference: 1})
        //镜像渐开线
        this.crownCADPlugin.command.sketch.createMirror({
          elementIds: [this.EquationId],
          axisId: this.axisId,
        })

        //绘制齿根圆
        this.crownCADPlugin.command.sketch.createCircle({
          centerPoint: new Point(0, 0, 0),
          circlePoint: new Point(0, 0.5* this.df2, 0),
        })
        //绘制喉圆半径+1
        this.crownCADPlugin.command.sketch.createCircle({
          centerPoint: new Point(0, 0, 0),
          circlePoint: new Point(0, 0.5* this.da2 + 1, 0),
        })

        this.crownCADPlugin.command.sketch.exitEditSketch({sketchName: '草图0'});
        await this.crownCADPlugin.command.execute()
        this.crownCADPlugin.command.clearCommand();

        //获取渐开线和镜像线的id
        await this.getLineInfo()

        this.crownCADPlugin.command.clearCommand();
        //编辑草图0
        this.crownCADPlugin.command.sketch.editSketch({sketchName: '草图0'});

        let  s = this.EquationS;
        let  s1 = this.EquationS1;

        //连接渐开线底边
        this.crownCADPlugin.command.sketch.createArcByCenter({
          centerPoint: new Point(0,0,0),
          startPoint: new Point(s1[0],s1[1],0),
          endPoint: new Point(s[0],s[1],0)});

        //删除df2圆
        this.crownCADPlugin.command.sketch.deleteElements({
          elementIds:[this.df2id],
        });

        //裁剪da2圆
        this.crownCADPlugin.command.sketch.createAutoTrimCurve({
          trimCurveId: this.da2id,
          trimCurvePoint: new Point( (0.5*this.da2 + 1)*-1,0,0),
        });

        //裁剪da2圆
        this.crownCADPlugin.command.sketch.createAutoTrimCurve({
          trimCurveId: this.da2id,
          trimCurvePoint: new Point( (0.5*this.da2 + 1),0,0),
        });

        //裁剪两条渐开线，最终获得齿形
        this.crownCADPlugin.command.sketch.createAutoTrimCurve({
          trimCurveId: this.EquationId,
          trimCurvePoint: new Point( this.EquationP['0'],this.EquationP['1'],0),
        })

        this.crownCADPlugin.command.sketch.createAutoTrimCurve({
          trimCurveId: this.EquationId1,
          trimCurvePoint: new Point(this.EquationP1['0'],this.EquationP1['1'],0),
        })

        this.crownCADPlugin.command.sketch.exitEditSketch({sketchName: '草图0'});
        await this.crownCADPlugin.command.execute()

        //清空command
        this.crownCADPlugin.command.clearCommand();
        //创建草图，命名为草图1
        this.crownCADPlugin.command.sketch.createSketch({sketchName: '草图1', datumId: 8});

        //绘制分度圆
        this.crownCADPlugin.command.sketch.createCircle({
          centerPoint: new Point(0, 0, 0),
          circlePoint: new Point(0, 0.5 * this.de2, 0),
        })

        //退出草图
        this.crownCADPlugin.command.sketch.exitSketch();
        //实现草图操作，参数true会覆盖之前的草图，不传则不会
        await this.crownCADPlugin.command.execute()
        //拉伸草图1获得蜗轮轴
        await this.createExtrude()

        this.crownCADPlugin.command.clearCommand();
        //创建草图，命名为草图2
        this.crownCADPlugin.command.sketch.createSketch({sketchName: '草图2', datumId: 22});
        //绘制该圆进行旋转切除
        this.crownCADPlugin.command.sketch.createCircle({
          centerPoint: new Point(0, this.a, 0),
          circlePoint: new Point(0, 0.5* this.da2, 0),
        })
        //退出草图
        this.crownCADPlugin.command.sketch.exitSketch();
        await this.crownCADPlugin.command.execute()

        //草图2进行旋转
        await this.revolveCut()

        //绘制封闭图形草图3，进行防干涉切除
        await this.createClosedFigure()

        //根据草图3进行旋转切除，得到旋转切除1
        await this.revolveCut1()

        //清空command
        this.crownCADPlugin.command.clearCommand()

        //绘制草图4，绘制螺旋线
        this.crownCADPlugin.command.sketch.createSketch({sketchName: '草图4', datumId: 22});

        //绘制螺旋线的圆
        this.crownCADPlugin.command.sketch.createCircle({
          centerPoint: new Point(0, this.a, 0),
          circlePoint: new Point(0, this.a - 0.5* this.d1, 0),
        })

        this.crownCADPlugin.command.sketch.exitSketch();
        await this.crownCADPlugin.command.execute()
        this.crownCADPlugin.command.clearCommand()

        //绘制螺旋线
        await this.createHelixCurve()

        //齿形依据螺旋曲线进行扫描切除
        await this.sweepCut()

        //圆周阵列特征无法实现，固圆周整列实体，然后再布尔交运算
        await this.createCircularPattern()

        this.loading = false
      },

      //创建蜗轮-原版
      async creatWormGear1() {
        this.loading = true
        // 更新数据
        this.updateData()

        //创建草图，命名为草图0，准备画齿形
        this.crownCADPlugin.command.sketch.createSketch({sketchName: '草图0', datumId: 8});
        // 绘制渐开线
        this.crownCADPlugin.command.sketch.createEquationCurve({
          equationType: 2,
          coordinateType: 1,
          equation1: 0.5* this.db + "*(sin(t+pi/2+0.024)-t*cos(t+pi/2+0.024))",
          equation2: 0.5* this.db + "*(t*sin(t+pi/2+0.024)+cos(t+pi/2+0.024))",
          startValue: 0,
          endValue: 1
        });
        // 绘制镜像轴
        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(0,0,0),
          endPoint:new Point( 0,0.5* this.de2 + 10,0)
        })
        //退出草图
        this.crownCADPlugin.command.sketch.exitSketch();
        //实现草图操作，参数true会覆盖之前的草图，不传则不会
        await this.crownCADPlugin.command.execute(true)

        this.crownCADPlugin.command.clearCommand();

        //获取渐开线和镜像线的id
        await this.getLineInfo()

        //编辑草图0
        this.crownCADPlugin.command.sketch.editSketch({sketchName: '草图0'});
        // 创建镜像线
        // this.crownCADPlugin.command.sketch.createSketchLine({
        //   startPoint: new Point(0,0,0),
        //   endPoint:new Point( 0,200,0)
        // })
        //设置镜像线
        this.crownCADPlugin.command.sketch.setReference({curveIds: [this.axisId], reference: 1})
        //镜像渐开线
        this.crownCADPlugin.command.sketch.createMirror({
          elementIds: [this.EquationId],
          axisId: this.axisId,
        })

        //绘制齿根圆
        this.crownCADPlugin.command.sketch.createCircle({
          centerPoint: new Point(0, 0, 0),
          circlePoint: new Point(0, 0.5* this.df2, 0),
        })
        //绘制喉圆半径+1
        this.crownCADPlugin.command.sketch.createCircle({
          centerPoint: new Point(0, 0, 0),
          circlePoint: new Point(0, 0.5* this.da2 + 1, 0),
        })

        this.crownCADPlugin.command.sketch.exitEditSketch({sketchName: '草图0'});
        await this.crownCADPlugin.command.execute()
        this.crownCADPlugin.command.clearCommand();

        //获取渐开线和镜像线的id
        await this.getLineInfo()

        this.crownCADPlugin.command.clearCommand();
        //编辑草图0
        this.crownCADPlugin.command.sketch.editSketch({sketchName: '草图0'});

        //裁剪df2圆
        this.crownCADPlugin.command.sketch.createAutoTrimCurve({
          trimCurveId: this.df2id,
          trimCurvePoint: new Point( 0.5*this.df2*-1,0,0),
        });

        //裁剪da2圆
        this.crownCADPlugin.command.sketch.createAutoTrimCurve({
          trimCurveId: this.da2id,
          trimCurvePoint: new Point( (0.5*this.da2 + 1)*-1,0,0),
        });
        //裁剪df2圆
        this.crownCADPlugin.command.sketch.createAutoTrimCurve({
          trimCurveId: this.df2id,
          trimCurvePoint: new Point( 0.5*this.df2,0,0),
        });

        //裁剪da2圆
        this.crownCADPlugin.command.sketch.createAutoTrimCurve({
          trimCurveId: this.da2id,
          trimCurvePoint: new Point( (0.5*this.da2 + 1),0,0),
        });

        // 裁剪两条渐开线，最终获得齿形
        this.crownCADPlugin.command.sketch.createAutoTrimCurve({
          trimCurveId: this.EquationId,
          trimCurvePoint: new Point( this.EquationP['0'],this.EquationP['1'],0),
        })
        this.crownCADPlugin.command.sketch.createAutoTrimCurve({
          trimCurveId: this.EquationId,
          trimCurvePoint: new Point( this.EquationS['0'],this.EquationS['1'],0),
        })

        this.crownCADPlugin.command.sketch.createAutoTrimCurve({
          trimCurveId: this.EquationId1,
          trimCurvePoint: new Point(this.EquationP1['0'],this.EquationP1['1'],0),
        })
        this.crownCADPlugin.command.sketch.createAutoTrimCurve({
          trimCurveId: this.EquationId1,
          trimCurvePoint: new Point(this.EquationS1['0'],this.EquationS1['1'],0),
        })

        this.crownCADPlugin.command.sketch.exitEditSketch({sketchName: '草图0'});
        await this.crownCADPlugin.command.execute()

        //清空command
        this.crownCADPlugin.command.clearCommand();
        //创建草图，命名为草图1
        this.crownCADPlugin.command.sketch.createSketch({sketchName: '草图1', datumId: 8});

        //绘制分度圆
        this.crownCADPlugin.command.sketch.createCircle({
          centerPoint: new Point(0, 0, 0),
          circlePoint: new Point(0, 0.5 * this.de2, 0),
        })

        //退出草图
        this.crownCADPlugin.command.sketch.exitSketch();
        //实现草图操作，参数true会覆盖之前的草图，不传则不会
        await this.crownCADPlugin.command.execute()
        //拉伸草图1获得蜗轮轴
        await this.createExtrude()

        this.crownCADPlugin.command.clearCommand();
        //创建草图，命名为草图2
        this.crownCADPlugin.command.sketch.createSketch({sketchName: '草图2', datumId: 22});
        //绘制该圆进行旋转切除
        this.crownCADPlugin.command.sketch.createCircle({
          centerPoint: new Point(0, this.a, 0),
          circlePoint: new Point(0, 0.5* this.da2, 0),
        })
        //退出草图
        this.crownCADPlugin.command.sketch.exitSketch();
        await this.crownCADPlugin.command.execute()

        //草图2进行旋转
        await this.revolveCut()

        //绘制封闭图形，进行防干涉切除
        await this.createClosedFigure()

        //根据草图3进行旋转切除，得到旋转切除1
        await this.revolveCut1()
        //清空command
        this.crownCADPlugin.command.clearCommand()

        //绘制草图4，绘制螺旋线
        this.crownCADPlugin.command.sketch.createSketch({sketchName: '草图4', datumId: 22});

        //绘制螺旋线的圆
        this.crownCADPlugin.command.sketch.createCircle({
          centerPoint: new Point(0, this.a, 0),
          circlePoint: new Point(0, this.a - 0.5* this.d1, 0),
        })

        this.crownCADPlugin.command.sketch.exitSketch();
        await this.crownCADPlugin.command.execute()
        this.crownCADPlugin.command.clearCommand()

        //绘制螺旋线
        await this.createHelixCurve()

        //齿形依据螺旋曲线进行扫描切除
        await this.sweepCut()

        //圆周阵列特征无法实现，固圆周整列实体，然后再布尔交运算
        await this.createCircularPattern()

	      this.loading = false
      },

      //拉伸创建花键轴或者花键孔
      async createExtrude() {
        this.crownCADPlugin.command.clearCommand();
        // let res= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETFEATURESBYNAMES, {featureNames: ["草图1"]})

        let res= await this.crownCADPlugin.query.getFeaturesByNames(['草图1'])

        // let res1= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETENTITIESBYFEATUREIDS, {featureIds: [res.features[0]?.id]})
        let res1= await this.crownCADPlugin.query.getEntitiesByFeatureIds([res.data.features[0]?.id]);

        await this.crownCADPlugin.command.solid.extrudeIncrement({
          sketch: res1.data.entities[0]?.id,
          height1: this.b2,
          extrudeType1: 4
        }, "拉伸凸台");
      },

      //草图2进行旋转切除
      async revolveCut() {
        this.crownCADPlugin.command.clearCommand();

        //获取草图2信息
        let res= await this.crownCADPlugin.query.getFeaturesByNames(['草图2'])
        // let res= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETFEATURESBYNAMES, {featureNames: ["草图2"]})

        //获取草图草图2中元素的信息
        let res1= await this.crownCADPlugin.query.getEntitiesByFeatureIds([res.data.features[0]?.id])
        // let res1= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETENTITIESBYFEATUREIDS, {featureIds: [res.data.features[0]?.id]})

        //获取拉伸凸台信息
        let res2= await this.crownCADPlugin.query.getFeaturesByNames(['拉伸凸台'])
        // let res2= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETFEATURESBYNAMES, {featureNames: ["拉伸凸台"]})

        //获取拉伸凸台entitiesid
        let res3= await this.crownCADPlugin.query.getEntitiesByFeatureIds([res2.data.features[0]?.id])
        // let res3= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETENTITIESBYFEATUREIDS, {featureIds: [res2.data.features[0]?.id]})

        let basePnt = new Point(0, 0, 0);
        let endPnt = new Point(0, 0, 10);
        const axis = new Axis();
        axis.setPoint(basePnt, endPnt);
        //对草图2进行旋转切除
        await this.crownCADPlugin.command.solid.revolveCutIncrement({
          sketch: res1.data.entities[0]?.id,
          axis: axis,
          reverse: 0,
          revolveType1: 0,
          angle1: 360,
          cutSolids: [res3.data.entities[0]?.id] },"旋转切除")
      },

      //绘制封闭图形，进行防干涉切除，右基准面画直线，起点xt，与y轴夹角Γ（Γ=arcsin（b2/d1））（34.85°），长度2b2，形成封闭图形
      async createClosedFigure() {
        //找到夹角
        let j =Math.asin(this.b2 / this.d1)
        //计算出4个顶点
        let a= new Point(-1* 2* this.b2* Math.sin(j), this.a- 2* this.b2* Math.cos(j), 0)

        let b= new Point(-1* 2* this.b2* Math.sin(j), this.a+5, 0)

        let c= new Point(2* this.b2* Math.sin(j), this.a+5, 0)

        let d= new Point(2* this.b2* Math.sin(j), this.a- 2* this.b2* Math.cos(j), 0)

        this.crownCADPlugin.command.clearCommand();
        //绘制草图3
        this.crownCADPlugin.command.sketch.createSketch({sketchName: '草图3', datumId: 22});
        //根据4条直线形成包围图形
        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: new Point(0, this.a, 0),
          endPoint:a
        })
        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: a,
          endPoint:b
        })
        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: b,
          endPoint:c
        })
        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: c,
          endPoint:d
        })
        this.crownCADPlugin.command.sketch.createSketchLine({
          startPoint: d,
          endPoint:new Point(0, this.a, 0)
        })
        this.crownCADPlugin.command.sketch.exitSketch();
        await this.crownCADPlugin.command.execute()
        this.crownCADPlugin.command.clearCommand();
      },

      //根据草图3进行旋转切除，得到旋转切除1
      async revolveCut1() {
        this.crownCADPlugin.command.clearCommand();

        let res= await this.crownCADPlugin.query.getFeaturesByNames(['草图3'])
        // let res= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETFEATURESBYNAMES, {featureNames: ["草图3"]})

        let res1= await this.crownCADPlugin.query.getEntitiesByFeatureIds([res.data.features[0]?.id])
        // let res1= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETENTITIESBYFEATUREIDS, {featureIds: [res.features[0]?.id]})


        let res2= await this.crownCADPlugin.query.getFeaturesByNames(['旋转切除'])
        // let res2= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETFEATURESBYNAMES, {featureNames: ["旋转切除"]})


        let res3= await this.crownCADPlugin.query.getEntitiesByFeatureIds([res2.data.features[0]?.id])
        // let res3= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETENTITIESBYFEATUREIDS, {featureIds: [res2.features[0]?.id]})

        let basePnt = new Point(0, 0, 0);
        let endPnt = new Point(0, 0, 10);
        const axis = new Axis();
        axis.setPoint(basePnt, endPnt);
        await this.crownCADPlugin.command.solid.revolveCutIncrement({
          sketch: res1.data.entities[0]?.id,
          axis: axis,
          reverse: 0,
          revolveType1: 0,
          angle1: 360,
          cutSolids: [res3.data.entities[0]?.id] },"旋转切除1");
      },

      // 获取草图0中各种线的信息
      async getLineInfo() {
        //根据草图名称草图0，获取草图信息
        let res= await this.crownCADPlugin.query.getFeaturesByNames(['草图0'])
        // let res= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETFEATURESBYNAMES, {featureNames: ["草图0"]})
        //获取草图草图0中元素的信息
        let result= await this.crownCADPlugin.query.getElementsByFeatureId(res.data.features[0]?.id)
        // let result= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETElEMENTSBYFEATURE, {featureId: res.data.features[0]?.id})

        result.data.elements.forEach(element => {
          //获取绘制的渐开线信息，20类型为渐开线
          if(element.type===8 && element.params.type=== 20 && element.params.startPoint[0]< 0) {
            this.EquationId= element.id
            this.EquationP= element.params.endPoint
            this.EquationS= element.params.startPoint
          }
          //获取镜像获得的渐开线信息，20类型为渐开线
          if(element.type===8 && element.params.type=== 20 && element.params.startPoint[0]> 0) {
            this.EquationId1= element.id
            this.EquationP1= element.params.endPoint
            this.EquationS1= element.params.startPoint
          }
          //获取df2圆的id
          if(element.type===8 && element.params.type=== 11 && element.params.startPoint[0]=== 0.5* this.df2) {
            this.df2id= element.id
          }

          //获取da2圆的id
          if(element.type===8 && element.params.type=== 11 && element.params.startPoint[0]=== 0.5* this.da2 + 1) {
            this.da2id= element.id
          }

          //获取镜像线的id
          if(element.type===8 && element.params.type=== 10) {
            this.axisId= element.id
          }
        })
      },

      //绘制螺旋线
      async createHelixCurve() {
        //获取草图4信息
        let res= await this.crownCADPlugin.query.getFeaturesByNames(['草图4'])
        // let res= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETFEATURESBYNAMES, {featureNames: ["草图4"]})

        if (res?.data.features) {
          //获取草图entitiesid
          let res1= await this.crownCADPlugin.query.getEntitiesByFeatureIds([res.data.features[0]?.id])
          // let res1= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETENTITIESBYFEATUREIDS, {featureIds: [res.data.features[0]?.id]})

          if (res1?.data.entities) {
            //穿件螺旋曲线
            await this.crownCADPlugin.command.curve.createHelixCurveIncrement({
              helixPlane: res1.data.entities[0]?.id,
              inputModel: 0,
              step: this.I,
              height: parseInt(this.I),
              rotation: 0,
              isInvert: 1,
              startAngle: 90
            },'螺旋曲线')
          }
        }
      },

      //齿形依据螺旋曲线进行扫描切除
      async sweepCut() {
        this.crownCADPlugin.command.clearCommand();
        //获取草图0的信息
        let res= await this.crownCADPlugin.query.getFeaturesByNames(['草图0'])
        // let res= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETFEATURESBYNAMES, {featureNames: ["草图0"]})
        if (res?.data.features) {
          //获取草图0元素信息
          let res1= await this.crownCADPlugin.query.getEntitiesByFeatureIds([res.data.features[0]?.id])
          // let res1= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETENTITIESBYFEATUREIDS, {featureIds: [res.data.features[0]?.id]})
          //获取旋转切除1实体的信息
          let ferRes= await this.crownCADPlugin.query.getFeaturesByNames(['旋转切除1'])
          // let ferRes= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETFEATURESBYNAMES, {featureNames: ["旋转切除1"]})
          //获取旋转切除1实体的entitiyid
          let ferRes1= await this.crownCADPlugin.query.getEntitiesByFeatureIds([ferRes.data.features[0]?.id])
          // let ferRes1= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETENTITIESBYFEATUREIDS, {featureIds: [ferRes.data.features[0]?.id]})
          //获取螺旋曲线的信息
          let ferRes2= await this.crownCADPlugin.query.getFeaturesByNames(['螺旋曲线'])
          // let ferRes2= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETFEATURESBYNAMES, {featureNames: ["螺旋曲线"]})
          //获取螺旋曲线的entitiyid
          let ferRes3= await this.crownCADPlugin.query.getEntitiesByFeatureIds([ferRes2.data.features[0]?.id])
          // let ferRes3= await this.crownCADPlugin.request.execFunction(PluginFunctionType.GETENTITIESBYFEATUREIDS, {featureIds: [ferRes2.data.features[0]?.id]})
          //齿形依据螺旋曲线进行扫描切除
          await this.crownCADPlugin.command.solid.sweepCutIncrement({
            sweepType: 0,
            sweepProfile:res1.data.entities[0]?.id,
            sweepPath:[ferRes3.data.entities[0]?.id],
            sweepDirection: 1,
            profileDirection:2,
            cutSolids: [ferRes1.data.entities[0]?.id]
          }, "扫描切除");
        }
      },

      //圆周阵列特征无法实现，固圆周整列实体，然后再布尔交运算
      async createCircularPattern() {
        this.crownCADPlugin.command.clearCommand();
        //创建阵列中心轴
        let basePnt = new Point(0, 0, 0);
        let endPnt = new Point(0, 0, 10);
        const axis = new Axis();
        axis.setPoint(basePnt, endPnt);

        //获取扫描切除的实体信息
        let res= await this.crownCADPlugin.query.getEntitiesByFeatureNames(['扫描切除'])
        // let res=  await this.crownCADPlugin.request.execFunction(PluginFunctionType.getEntitiesByFeatureNames, {featureNames: ["扫描切除"]})
        if (res?.data.entities) {
          //阵列创建阵列中心轴
          // this.crownCADPlugin.command.solid.circularPattern({
          //   baseType: 1,
          //   features: [res.features[0]?.id],
          //   axis: axis,
          //   angle1: 360,
          //   instanceNum1: this.z2,
          // }, "圆周阵列");

          //进行实体阵列
          await this.crownCADPlugin.command.solid.circularPatternIncrement({
            baseType: 0,
            // features: [res.features[0]?.id],
            body:res.data.entities[0]?.id,
            axis:  axis,
            angle1: 360,
            instanceNum1: this.z2,
            equalSpacing1: 1
          }, "圆周阵列");
        }
        // 布尔交运算
        await this.booleanIntersect()
      },

      // 布尔交运算
      async booleanIntersect() {
        this.crownCADPlugin.command.clearCommand();
        //获取所以实体信息
        let res= await this.crownCADPlugin.query.getEntities()
        // 留下布尔交的实体
        let entityId= []
        console.log(res);
        res.data.entities.forEach(entity => {
          if(entity.name.indexOf('圆周阵列')!== -1|| entity.name=== '扫描切除')
            entityId.push(entity.id)
        })

        await this.crownCADPlugin.command.solid.booleanIntersectIncrement({
          entitys: entityId,
          keep: 0, },"布尔交")
      }
    }
  }
</script>

<style scoped>
  >>> .el-form-item {
    margin-bottom: 0!important;
  }
  >>> .el-form-item__label {
    margin-bottom: 0!important;
  }
</style>
